package com.m1.tzolkin.model.buildables;

import com.m1.tzolkin.model.IAction;
import com.m1.tzolkin.model.ITZStock;
import com.m1.tzolkin.model.board.ITZBoard;
import com.m1.tzolkin.model.exceptions.NoAvailableSkullException;
import com.m1.tzolkin.model.exceptions.NotAvailableActionException;
import com.m1.tzolkin.model.exceptions.NotEnoughCornException;
import com.m1.tzolkin.model.players.ITZPlayer;

public abstract class AbsActionBuildable extends Buildable implements
		IActionBuildable {

	// ATTRIBUTS
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1688210906355467727L;
	private final BuildableType type;
	private final IAction action;
	private ITZPlayer owner;
	
	// CONSTRUCTEUR
	
	public AbsActionBuildable(ITZStock cost, BuildableType type, IAction action) {
		super(cost);
		if (type == null || action == null) {
			throw new IllegalArgumentException();
		}
		this.type = type;
		this.action = action;
	}
	
	// REQUETES
	
	@Override
	public BuildableType getType() {
		return type;
	}

	// COMMANDES
	
	@Override
	public void setOwner(ITZPlayer p) {
		if (p == null) {
			throw new IllegalArgumentException();
		}
		owner = p;
	}
	
	@Override
	public void active(ITZBoard b, ITZPlayer p) throws NoAvailableSkullException, NotEnoughCornException, NotAvailableActionException {
		action.doAction(b, owner);
	}

}
